
package cn.dnui_cjy529.dnuifood_16110100529.model;

import android.provider.SyncStateContract;

import javax.xml.transform.Result;

import cn.dnui_cjy529.dnuifood_16110100529.bean.ResultBean;
import cn.dnui_cjy529.dnuifood_16110100529.iface.UserIface;
import cn.dnui_cjy529.dnuifood_16110100529.listener.OnRetrofitListener;
import cn.dnui_cjy529.dnuifood_16110100529.service.UserService;
import retrofit2.Call;


import cn.dnui_cjy529.dnuifood_16110100529.bean.UserBean;

import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;



//public class UserModel extends BaseModel implements UserIface {
//
//    private Retrofit retrofit;
//
//
//    private UserService service;
//    private String BaseUrl="http://172.24.10.175:8080/foodService/";
//    public UserModel() {
//        retrofit = new Retrofit.Builder().baseUrl(BaseUrl).addConverterFactory(GsonConverterFactory.create()).build();
//
//        service = retrofit.create(UserService.class);
//    }
//
//
//    @Override
//    public void login(String username, String userpass, final OnRetrofitListener listener) {
//        Call<UserBean> call = service.userLogin(username, userpass);
//        call.enqueue(new Callback<UserBean>() {
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//                if (response.body() != null)
//                    listener.onSuccess(response.body(), 1);
//                else
//                    listener.onFailure("解析失败");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                listener.onFailure("联网失败");
//            }
//        });
//    }
//
//
//
//    @Override
//    public void register(String username, String userpass, String monilenum, String address, String comment, final OnRetrofitListener listener) {
//        Call<ResultBean> call = service.doregister(username, userpass,monilenum,address,comment);
//        call.enqueue(new Callback<ResultBean>() {
//            @Override
//            public void onResponse(Call<ResultBean> call, Response<ResultBean> response) {
//                if (response.body() != null)
//                    listener.onSuccess(response.body(), 2);
//                else
//                    listener.onFailure("解析失败");
//            }
//
//            @Override
//            public void onFailure(Call<ResultBean> call, Throwable t) {
//                listener.onFailure("联网失败");
//            }
//        });
//    }
//
//    }
//
//
public abstract class UserModel extends BaseModel implements UserIface {
    private UserService userService;
    public UserModel(){
       userService=retrofit.create(UserService.class);
    }
    public void login(String username,String password,final OnRetrofitListener listener){
        Call call=userService.userLogin(username,password);
        bindCallback(call,listener, SyncStateContract.Constants.USERLOGIN );
    }
    public void reg(String username,String userpass,String mobilenum,String address,String comment,final OnRetrofitListener listener){
        Call call=userService.doregister(username,userpass,mobilenum,address,comment);
        bindCallback(call,listener, SyncStateContract.Constants.USERREGISTER);
    }}